package exception;

public class Student {
    String name;
    int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) throws ageException{//方法继续抛出异常，谁调用谁处理异常
        if (age<0) throw new ageException();
        this.age = age;
    }
    public static void main(String[] agrs){
        Student s=new Student();
        try {
            s.setAge(-6);
        } catch (ageException e) {
            System.out.println(e.getMessage());
        }
    }
}
